#include "ComThread.hpp"
#include "newForm.h"
#include <iostream>

ComThread::ComThread(PilhaClient* pilha, newForm* nf, Jogador* este) {

    this->guif = nf;
    this->p = pilha;
    this->j = este;
}

ComThread::~ComThread() {

}

void ComThread::run() {

    unsigned char* ch = new unsigned char[2];
    int j;
    int i;
    while (true) {

        std::cout << "Lendo" << std::endl;
        this->p->le(ch, 2);
        i = ch[0] - '0';
        j = ch[1] - '0';

        std::cout << "Up: " << i << " - " << j << std::endl;
        if (i == 0) {

            if (j == 0) {

                this->guif->botao1(true);
                this->guif->update();
            } else if (j == 1) {

                this->guif->botao2(true);
            } else if (j == 2) {

                this->guif->botao3(true);
            }
        } else if (i == 1) {

            if (j == 0) {

                this->guif->botao4(true);
            } else if (j == 1) {

                this->guif->botao5(true);
            } else if (j == 2) {

                this->guif->botao6(true);
            }
        } else if (i == 2) {

            if (j == 0) {

                this->guif->botao7(true);
            } else if (j == 1) {

                this->guif->botao8(true);
            } else if (j == 2) {

                this->guif->botao9(true);
            }
        }
    }
    
    delete ch;
}
